import ajax from "./../../api";

const state = {
  account_name: null,
  user_name: ""
};

var getters = {
  user_name(state) {
    return state.user_name;
  }
};

const actions = {
  reload(context) {
    return ajax.profile
      .profile_info()
      .then(response => {
        if (response.code == 1) {
          context.commit("reload", response.data);
          return true;
        } else {
          return false;
        }
      })
      .catch(e => {
        console.log(e);
        return false;
      });
  }
};

const mutations = {
  reload(state, payload) {
    state.account_name = payload.account_name;
    state.user_name = payload.real_name;
  }
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
};
